package com.yang.aiDoctor.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


@RestController
@RequestMapping("/test")
public class TestController {
    @Value("${spring.datasource.url}")
    String url;
    @Value("${spring.datasource.username}")
    String userName;
    @Value("${spring.datasource.password}")
    String passWord;
    /**
     * test测试接口
     * @return string
     */
    @RequestMapping("/hello")
    public String HController() {
        return "Hello Controller";
    }

    @GetMapping("/dbCheck")
    public String checkDbConnection() throws SQLException {
        Connection connection = DriverManager.getConnection(url, userName, passWord);
        boolean closed = connection.isClosed();
        return connection.toString()+"\n"+"Mysql link Closed:"+closed;
    }
}
